﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; 
using Microsoft.JCI.Dal;
using System.Data;
using Microsoft.JCI.Common.Entity;
using Microsoft.JCI.Common.Utility; 
using System.Transactions;

namespace Microsoft.JCI.Bll
{
    public class DispatchBll:BllBase
    {
        public DataTable QueryDispatchForm(List<SqlDbParameter> Conditions)
        {
            DisDispatchFormDal dal = new DisDispatchFormDal();
            return dal.QueryDispatchForm(Conditions);
        }

        public string GetDispatchFormCode()
        {
            Util u = new Util();
            SysAutoCodeRuleEntity entity = u.GetEntity("DispatchCode");
            if (entity != null)
            {
                if (entity.ResetType == 0)
                    return string.Format(entity.RuleFormat, entity.Seed);
                else
                    return string.Format(entity.RuleFormat,DateTime.Now, entity.Seed);
            }

            return string.Empty;
        }

        /// <summary>
        /// 保存工作单
        /// </summary>
        /// <param name="OrderEntity"></param>
        /// <param name="ItemEntity"></param>
        /// <param name="CustomerEntity"></param>
        public void SaveNewWorkingOrder(DisWorkingVendorOrderEntity OrderEntity,DisWorkingVendorItemEntity ItemEntity,MadCustomerEntity CustomerEntity)
        {
            using (System.Transactions.TransactionScope tran = new TransactionScope())
            {
                if(OrderEntity != null)
                    base.InsertOrUpdate(OrderEntity);

                if (ItemEntity != null) base.InsertOrUpdate(ItemEntity);

                if (CustomerEntity != null) base.InsertOrUpdate(CustomerEntity);

                tran.Complete();
            }
        }


        public DataTable QueryWorkItems(string WhereClause, int PageSize, int PageIndex, ref int RecordCount)
        {
            DisWorkingVendorOrderDal dal = new DisWorkingVendorOrderDal();
            return dal.QueryWorkItems(WhereClause, PageSize, PageIndex, ref RecordCount);
        }

    }
}
